const { createProxyMiddleware } = require('http-proxy-middleware');

// According to:
// https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually
module.exports = function(app) {
  app.use(
    '/douban',
    createProxyMiddleware({
      target: 'https://img9.doubanio.com',
      changeOrigin: true,
      pathRewrite: {
        '^/douban' : '/'
      },
      headers: {
        "Referer": "https://movie.douban.com"
      }
    })
  );


  app.use(
    '/hs-img',
    createProxyMiddleware({
      target: 'https://res.fbigame.com/',
      changeOrigin: true,
      pathRewrite: {
        '^/hs-img' : '/'
      },
      headers: {
        "Referer": "https://hs.fbigame.com/"
      }
    })
  );

  app.use(
    '/chouti',
    createProxyMiddleware({
      target: 'https://dig.chouti.com/',
      changeOrigin: true,
      pathRewrite: {
        '^/chouti': '/',
      },
      headers: {
        Referer: 'https://dig.chouti.com',
      },
    })
  )
  app.use(
    '/chouti-img',
    createProxyMiddleware({
      target: 'https://img3.chouti.com/',
      changeOrigin: true,
      pathRewrite: {
        '^/chouti-img': '/',
      },
      headers: {
        Referer: 'https://dig.chouti.com',
      },
    })
  )
};